//
//  BaseTableViewController.swift
//  Microblog
//
//  Created by steaest on 15/7/28.
//  Copyright © 2015年 steaest. All rights reserved.
//

//1.view = VisitorView() view是基类,无法调用VisitorView内的函数,要先声明一个变量接受

import UIKit

class BaseTableViewController: UITableViewController,VisitorViewDelegate {

    //访客视图
    var visitorView:VisitorView?
    //登录标记
    //var userLogon = UserAccount.loadAccount() != nil
    //var userLogon = false
    var userLogon = UserAccount.userLogon
    
    override func loadView() {
        userLogon ? super.loadView() : setUpVisitorView()
    }
    
    private func setUpVisitorView() {
        
        visitorView = VisitorView()
        visitorView?.delegate = self
        view = visitorView
        
        //设置状态栏
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewWillRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewWillLogin")
    }
    
    //MARK:代理方法
    func visitorViewWillRegister() {
        print("注册")
    }
    
    func visitorViewWillLogin() {
        
        let nav = UINavigationController(rootViewController: OAuthViewController())
        presentViewController(nav, animated: true, completion: nil)
    }
    
    
}
